import { IResponse } from "@/interface/IAxios";
import http from "../config/http";
import { updateFile } from "./utils";
// 登录方法
export function login(username: string, password: string) {
  const data = {
    username,
    password
  };
  return http.request({
    url: "/login",
    method: "post",
    data
  });
}

export function getUserProfile(): Promise<IResponse<any>> {
  return http.request({
    url: "/system/user/profile",
    method: "get"
  });
}

// 修改用户个人信息
export function updateUserProfile(data: any) {
  return http.request({
    url: "/system/user/profile",
    method: "put",
    data
  });
}

// 用户密码重置
export function updateUserPwd(oldPassword: string, newPassword: string) {
  const data = {
    oldPassword,
    newPassword
  };
  return http.request({
    url: "/system/user/profile/updatePwd",
    method: "put",
    params: data
  });
}
// 用户头像上传
export function uploadAvatar(data: File): Promise<IResponse<any>> {
  return new Promise((response) => {
    updateFile(data, "/system/user/profile/avatar").then((res) => {
      response(res.data);
    });
  });
}
export const updateLang = (lang: string) => {
  return http.request({
    url: `v2/sys/api/lang/${lang}`
  });
};
